package com.service.impl;

import com.mapper.ProductStatsMapper;
import com.service.SugerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: TODO QQ1667847363
 * @author: xiao kun tai
 * @date:2022/1/14 9:43
 */

@Service
public class SugerServiceImpl implements SugerService {

    @Autowired
    private ProductStatsMapper productStatsMapper;

    @Override
    public BigDecimal getGmv(int date) {
        return productStatsMapper.selectGmv(date);
    }

    @Override
    public Map getGmvByTm(int date, int limit) {

        //查询数据
        List<Map> mapList = productStatsMapper.selectGmvByTm(date, limit);



        //创建Map用于存放结果数据
        HashMap<String, BigDecimal> result = new HashMap<>();


        //遍历mapList，将数据取出放入result
        for (Map map : mapList) {
            result.put((String) map.get("tm_name"),(BigDecimal) map.get("order_amount"));
        }

        //返回结果集合
        return result;
    }
}
